﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Generate Statistical Reports</h2>

<script type="text/javascript">
    function rateditem() {
        $.ajax({
            url: '@Url.Action("HighlyRatedItem")',
            type: "POST",
            datatype: "html",
            UpdateTargetId: "divResult", // The DIV that will contain the partial view
            data: null, // Passing the parameters var
            error: function (xmlHttpRequest, errorText, thrownError) {
                alert("An error has occurred.");
            },
            success: function (data) {
                $('#divResult').empty();
                $('#divResult').html(data);
            }
        });
    }

    function purchaseditem() {
        $.ajax({
            url: '@Url.Action("MostPurchasedItem")',
            type: "POST",
            datatype: "html",
            UpdateTargetId: "divResult", // The DIV that will contain the partial view
            data: null, // Passing the parameters var
            error: function (xmlHttpRequest, errorText, thrownError) {
                alert("An error has occurred.");
            },
            success: function (data) {
                $('#divResult').empty();
                $('#divResult').html(data);
            }
        });
    }

    function highfaults() {
        $.ajax({
            url: '@Url.Action("HighestNoFaults")',
            type: "POST",
            datatype: "html",
            UpdateTargetId: "divResult", // The DIV that will contain the partial view
            data: null, // Passing the parameters var
            error: function (xmlHttpRequest, errorText, thrownError) {
                alert("An error has occurred.");
            },
            success: function (data) {
                $('#divResult').empty();
                $('#divResult').html(data);
            }
        });
    }

    function lowfaults() {
        $.ajax({
            url: '@Url.Action("LowestNoFaults")',
            type: "POST",
            datatype: "html",
            UpdateTargetId: "divResult", // The DIV that will contain the partial view
            data: null, // Passing the parameters var
            error: function (xmlHttpRequest, errorText, thrownError) {
                alert("An error has occurred.");
            },
            success: function (data) {
                $('#divResult').empty();
                $('#divResult').html(data);
            }
        });
    }
</script>

<button type="button" onclick="rateditem()">Highly Rated Item</button> <br /> <br />
<button type="button" onclick="purchaseditem()">Most Purchased Item</button> <br /> <br />
<button type="button" onclick="highfaults()">Highest Number of Faults</button> <br /> <br />
<button type="button" onclick="lowfaults()">Least Number of Faults</button> <br /> <br />

<br /> <br />
<div id = "divResult">
</div>